public class MainClass {

    public static void main(String[] args) {

        //        创建对象锁对象1
        SynchronizedObject so1 = new SynchronizedObject();


        Thread thread1 = new Thread(() -> so1.test1());
        Thread thread2 = new Thread(() -> so1.test1());

//        thread1.start();
//        thread2.start();

        /**结果
         * Thread-0test1------开始
         * Thread-0test1------结束
         * Thread-1test1------开始
         * Thread-1test1------结束
         *
         */

        //        创建对象锁对象2
        SynchronizedObject so2 = new SynchronizedObject();

        Thread thread3 = new Thread(() -> so2.test2());
        Thread thread4 = new Thread(() -> so2.test2());

//        thread3.start();
//        thread4.start();

        /**结果
         * Thread-0test3------开始
         * Thread-0test3------结束
         * Thread-1test4------开始
         * Thread-1test4------结束
         *
         */

        // 创建类锁对象1（锁静态方法）
        SynchronizedClass sc1 = new SynchronizedClass();
        // 创建类锁对象2（锁静态方法）
        SynchronizedClass sc2 = new SynchronizedClass();

        // 调用不同对象的加了锁的静态方法
        Thread thread5 = new Thread(() -> sc1.method1());
        Thread thread6 = new Thread(() -> sc2.method1());

//        thread5.start();
//        thread6.start();

        /**结果：
         *   Thread-4method1------开始
         *   Thread-4method1------结束
         *   Thread-5method1------开始
         *   Thread-5method1------结束
         */

        // 调用不同对象的加了类锁的代码块的方法
        Thread thread7 = new Thread(() -> sc1.method2());
        Thread thread8 = new Thread(() -> sc2.method2());

        thread7.start();
        thread8.start();

        /**结果
         *
         * Thread-6method2------开始
         * Thread-6method2------结束
         * Thread-7method2------开始
         * Thread-7method2------结束
         */






    }
}
